<?php

namespace addons\exam\controller;
use app\admin\model\xmk\Enrollmennews;
use app\admin\model\xmk\Enrollmentplan;

class School extends Base
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    /**
     * School模型对象
     * @var \app\admin\model\xmk\School
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\xmk\School;
    }
    /**
     * 学校列表
     */
    public function index()
    {
        $where['status'] = 'normal';
        $key   = input('key');
        if($key){
            $where['name'] = ['like','%'.$key.'%'];
        }
        $data  = $this->model->where($where)->paginate();
        $this->success('ok',$data);
    }

    /**
     * 学校详情
     */

    public function detail(){
        $ids = input('ids');
        if(!$ids){
            $this->error('缺少参数');
        }
        $info = $this->model->where(['id'=>$ids,'status'=>'normal'])->find();
        $this->success('ok',$info);
    }

    /**
     * 招生新闻
     */

    public function enroll_news(){
        $model = new Enrollmennews();
        $ids   = input('ids');
        if(!$ids){
            $this->error('缺少参数');
        }
        $key   = input('key');
        $where['school_id'] = $ids;
        $where['status']    = 'normal';
        if($key){
            $where['title'] = ['like','%'.$key.'%'];
        }

        $data  = $model->where($where)->order('id desc')->paginate();
        $this->success('ok',$data);
    }

    /**
     * 招生新闻详情
     */

    public function zsdetail(){
        $model = new Enrollmennews();
        $ids   = input('ids');
        if(!$ids){
            $this->error('缺少参数');
        }
        $data  = $model->where(['id'=>$ids])->field('id,title,content,createtime')->find();
        $this->success('ok',$data);
    }

    /**
     * 招生计划
     */

    public function enroll_student(){
        $ids   = input('ids');
        if(!$ids){
            $this->error('缺少参数');
        }
        $model = new Enrollmentplan();
        $data  = $model->where(['school_id'=>$ids,'status'=>'normal'])->order('id desc')->find();
        $this->success('ok',$data);
    }

}
